package com.sse.product.controller.rbac;


import com.sse.product.common.ResultCode;
import com.sse.product.rbac.entity.Menus;
import com.sse.product.model.rbac.ResponseVo;
import com.sse.product.rbac.service.IMenusService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author junyongli
 * @since 2022-07-22
 */
@RestController
@RequestMapping("/rbac/menu")
public class MenuController {

    // 功能不建议维护，与前端确认好菜单的uniqueName，进行权限控制即可。
    // 功能，可以当做具体的权限.
    @Autowired
    private IMenusService functionService;

    @ApiOperation(value = "查全部功能")
    @PostMapping("/queryAll")
    public ResponseVo queryAll() {
        return ResponseVo.assemble(ResultCode.SUCCESS, functionService.queryAll());
    }

    @ApiOperation(value = "新增功能")
    @PreAuthorize("hasAuthority('MENU-MANAGE')")
    @PostMapping("/add")
    public ResponseVo addMenu(@RequestBody Menus menus) {
        return ResponseVo.assemble(ResultCode.SUCCESS, functionService.addMenu(menus));
    }

    @ApiOperation(value = "更新功能")
    @PreAuthorize("hasAuthority('MENU-MANAGE')")
    @PostMapping("/update")
    public ResponseVo updateMenu(@RequestBody Menus menus) {
        return ResponseVo.assemble(ResultCode.SUCCESS, functionService.updateMenu(menus));
    }

    @ApiOperation(value = "删除功能")
    @PreAuthorize("hasAuthority('MENU-MANAGE')")
    @PostMapping("/delete")
    public ResponseVo delete(@RequestBody Menus menus) {
        return ResponseVo.assemble(ResultCode.SUCCESS, functionService.delMenu(menus));
    }

}
